﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml.Linq;
using SharedConfiguration;

namespace OfficeDownloaderHelper
{
    public static class XmlWriter
    {
        public static bool WriteConfigXML (Config configuracion)
        {
            try
            {
                XElement xmltree = new XElement("Configuration");
                foreach (var item in configuracion.Arquitectura)
                {
                    var add = new XElement("add", new XAttribute("OfficeClientEdition", item == ArquitecturaEnum.x86 ? "32" : "64"));
                    var producto = new XElement("Product", new XAttribute("ID", "O365ProPlusRetail"));
                    foreach (var lang in configuracion.Idiomas)
                    {
                        producto.Add(new XElement("Language", new XAttribute("ID", lang.idiomaKey)));
                    }
                    add.Add(producto);
                    xmltree.Add(add);
                }

                xmltree.Save(configuracion.Path + "config.xml");

                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
    }
}
